﻿//--------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// This source code is intended only as a supplement to Microsoft
// Development Tools and/or on-line documentation.  See these other
// materials for detailed information regarding Microsoft code samples.
// 
// THIS CODE AND INFORMATION ARE PROVIDED AS IS WITHOUT WARRANTY OF ANY
// KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//--------------------------------------------------------------------------------

//change this to change what is display on pushpin hover
var toolTip = "<div>{0}</div>";
var toolTipTitle = "{0}";
function addPin(lat, lng, title, color, description) {
    var shape = new VEShape(VEShapeType.Pushpin, new VELatLong(lat, lng));
    shape.SetTitle(title);
    var icon = "<img src='" + color + ".gif'/>";
    shape.SetCustomIcon(icon);
    shape.SetDescription(description);
    _theMap.AddShape(shape);

}
function onMouseClick(e) {
    if (e != null && e.elementID != null) {
        var shape = _theMap.GetShapeByID(e.elementID);
        if (e.leftMouseButton) {
            var el = $get("silverlightControlHost");
            var name = shape.GetTitle();
            //TODO: Add code here to get action to happen on click
        }

    }
}
var _theMap;
var _timer;
var _total;
var _quote;
var _limit = 0;

function pageLoad() {

    _theMap = new VEMap('myMap');
    _theMap.LoadMap(null, 2, 'h');
    window.onresize = resize;
    resize(null, null);
    _theMap.AttachEvent('onclick', onMouseClick);
 


}

function reset() {
    _theMap.DeleteAllShapes();
    _master = true;
}
var _master = true;

function resize(object, args) {
    var el = $get("silverlightControlHost");
    var el2 = $get("myMap");
    el2.style.left = el.offsetLeft + 25;
    el2.style.top = el.offsetTop + 50;
   

}

function clearPins() {
    _theMap.DeleteAllShapes();
}


function determineColor() {

    var perc = (_total * 100) / _limit;
    var color = new Object();
    if (perc <= 75) {
        color = 'red';

    }
    if (perc < 100 && perc > 75) {
        color = 'yellow';
    }
    if (perc > 100) {
        color = 'green';
    }
    return color;


}
String.format = function() {

    if (arguments.length == 0)

        return null;



    var str = arguments[0];



    for (var i = 1; i < arguments.length; i++) {

        var re = new RegExp('\\{' + (i - 1) + '\\}', 'gm');

        str = str.replace(re, arguments[i]);

    }



    return str;

}
if ($get == null)
    var $get = function(id) {
        return document.getElementById(id);
    }
